<template>
  <a-card :bordered="false" :class="'cust-erp-sub-tab'">
    <!-- 操作按钮区域 -->
    <div class="table-operator" v-if="mainId">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <button  @click="qqq()" type="button" class="ant-btn ant-btn-primary">
        <i aria-label="图标: database" class="anticon anticon-database">
          <svg viewBox="64 64 896 896" data-icon="database" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M832 64H192c-17.7 0-32 14.3-32 32v832c0 17.7 14.3 32 32 32h640c17.7 0 32-14.3 32-32V96c0-17.7-14.3-32-32-32zm-600 72h560v208H232V136zm560 480H232V408h560v208zm0 272H232V680h560v208zM304 240a40 40 0 1 0 80 0 40 40 0 1 0-80 0zm0 272a40 40 0 1 0 80 0 40 40 0 1 0-80 0zm0 272a40 40 0 1 0 80 0 40 40 0 1 0-80 0z"></path></svg></i>
        <span>生成数据集</span></button>
      <!--<a-button @click="handleAdd" type="primary" icon="plus">生成数据集</a-button>-->
      <!--<a-button type="primary" icon="download" @click="handleExportXls('ylsh_sjcjmbsjx')">导出</a-button>-->
      <!--<a-upload-->
        <!--name="file"-->
        <!--:showUploadList="false"-->
        <!--:multiple="false"-->
        <!--:headers="tokenHeader"-->
        <!--:action="importExcelUrl"-->
        <!--@change="handleImportExcel">-->
          <!--<a-button type="primary" icon="import">导入</a-button>-->
      <!--</a-upload>-->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>

      </a-table>
    </div>

    <ylshSjcjmbsjx-modal ref="modalForm" @ok="modalFormOk" :mainId="mainId"></ylshSjcjmbsjx-modal>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import YlshSjcjmbsjxModal from './modules/YlshSjcjmbsjxModal'
  import { getAction,youHuaId } from '@/api/manage'

  export default {
    name: "YlshSjcjmbsjxList",
    mixins:[JeecgListMixin],
    components: { YlshSjcjmbsjxModal },
    props:{
      mainId:{
        type:String,
        default:'',
        required:false
      }
    },
    watch:{
      mainId:{
        immediate: true,
        handler(val) {
          if(!this.mainId){
            this.clearList()
          }else{
            this.queryParam['sjcjmbId'] = val
            this.loadData(1);
          }
        }
      }
    },
    data () {
      return {
        description: 'ylsh_sjcjmb管理页面',
        disableMixinCreated:true,
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          // {
          //   title:'模板ID',
          //   align:"center",
          //   dataIndex: 'sjcjmbId'
          // },
          {
            title:'数据项名称',
            align:"center",
            dataIndex: 'sjxmc'
          },
          {
            title:'物理字段名称',
            align:"center",
            dataIndex: 'wlzdmc'
          },
          {
            title:'数据类型',
            align:"center",
            dataIndex: 'sjlx',
            customRender:function (text) {
              if(text=="varchar"){
                return "字符型";
              }else if(text=="int"){
                return "整型";
              }else if(text=="double"){
                return "浮点型";
              }else if(text=="date"){
                return "日期型";
              }else if(text=="tinyint"){
                return "布尔型";
              }else if(text=="decimal"){
                return "精准数据类型";
              }else{
                return text;
              }
            }
          },
          {
            title:'数据长度',
            align:"center",
            dataIndex: 'sjcd'
          },
          {
            title:'数据源',
            align:"center",
            dataIndex: 'sjy'
          },
          {
            title:'是否非空',
            align:"center",
            dataIndex: 'sffk',
            customRender: (text) => (text ? '为空' : '不为空'),
          },
          {
            title:'是否启用',
            align:"center",
            dataIndex: 'sfqy',
            customRender: (text) => (text ? '启用' : '停用'),
          },
          {
            title:'排序号',
            align:"center",
            dataIndex: 'pxh'
          },
          // {
          //   title:'排序号',
          //   align:"center",
          //   dataIndex: 'sfqy'
          // },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/sjcjmb/ylshSjcjmb/listYlshSjcjmbsjxByMainId?column=pxh&order=asc",
          delete: "/sjcjmb/ylshSjcjmb/deleteYlshSjcjmbsjx",
          deleteBatch: "/sjcjmb/ylshSjcjmb/deleteBatchYlshSjcjmbsjx",
          exportXlsUrl: "/sjcjmb/ylshSjcjmb/exportYlshSjcjmbsjx",
          importUrl: "/sjcjmb/ylshSjcjmb/importYlshSjcjmbsjx",
        },
        dictOptions:{
        },
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl(){
        return `${window._CONFIG['domianURL']}/${this.url.importUrl}/${this.mainId}`;
      }
    },
    methods: {
      qqq(){
        var DATA = youHuaId()
        getAction('/sjcjmb/ylshSjcjmb/createTable',{Id:DATA.id,Name:DATA.mbdysjb}).then(res=>{
          this.$message.success(res)
        })
      },
      clearList(){
        this.dataSource=[]
        this.selectedRowKeys=[]
        this.ipagination.current = 1
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'mbmc',text:'模板名称',dictCode:''})
        fieldList.push({type:'string',value:'mbdysjb',text:'模板对应数据表',dictCode:''})
        fieldList.push({type:'switch',value:'qyzt',text:'启用状态'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>
